<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>script脚本的加载(promise)</title>
</head>
<body>
    
</body>
<script>
    function loadJs(src){
        return new Promise((resolve, reject) => {
            const script = document.createElement('script');
            script.src = src;
            script.onload = () => resolve(script);
            script.onerror = () => reject(new Error(`Script load error: ${src}`));
            document.head.append(script);
        });
    }
    loadJs('./通过文件依赖了解任务排序/3-1.js')
    .then( script => {
        //注意把promise返回出去，交给下一个then处理，不要再后面直接处理，否则又会像回调函数一样形成回调地狱,失去了promise的扁平化
        return loadJs('./通过文件依赖了解任务排序/3-2.js');    
    })
    .then(script => {
        md();
    })
    .catch(error => {
        console.log(error);
    })
</script>
</html>